package com.wangzeqi.neihanduanzi.news.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.wangzeqi.neihanduanzi.R;
import com.wangzeqi.neihanduanzi.news.base.BaseText;

/**
 * Created by dllo on 16/1/26.
 */
public class NewsRootTextActivity extends AppCompatActivity{

    private TextView textTitle;
    private TextView textSource;
    private TextView textTime;
    private TextView textBody;
    private TextView textAuthor;
    private RequestQueue queue;
    private BaseText baseText;
    private BaseText.BDLI4I660001124JEntity baseText1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_root_text);
        textTitle = (TextView) findViewById(R.id.text_title);
        textSource = (TextView) findViewById(R.id.text_source);
        textTime = (TextView) findViewById(R.id.text_time);
        textBody = (TextView) findViewById(R.id.text_body);
        textAuthor = (TextView) findViewById(R.id.text_author);
        queue = Volley.newRequestQueue(this);
        Intent intent = getIntent();
        String s = intent.getStringExtra("text");

        String url = "http://c.3g.163.com/nc/article/" + s + "/full.html";
        baseText = new BaseText();
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                baseText1 = new BaseText.BDLI4I660001124JEntity();
                response = response.replace(response.substring(2, 18), "BDLI4I660001124J");
                Gson gson = new Gson();
                baseText = gson.fromJson(response, BaseText.class);
                baseText1 = baseText.getBDLI4I660001124J();
                if (baseText != null) {
                    textTitle.setText(baseText1.getTitle());
                    textSource.setText(baseText1.getSource());
                    textTime.setText(baseText1.getPtime());
                    textBody.setText(Html.fromHtml(baseText1.getBody()));
                    textAuthor.setText("(责任编辑: " + baseText1.getEc() + ")");

                }


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        queue.add(request);


    }
}
